/*
 *  Copright: 2008 Philipp Leitner, Distributed Systems Group,
 *            TU Wien, leitner@infosys.tuwien.ac.at
 *
 *  This file is part of DAIOS.
 *
 *  DAIOS is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as
 *  published by the Free Software Foundation.
 * 
 *  DAIOS is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with DAIOS.  If not, see
 *  <http://www.gnu.org/licenses/>.
 * 
 */

package at.ac.tuwien.infosys.dsg.daiosPlugins.nativeInvoker.converter;

import java.util.List;

import org.apache.axiom.om.OMElement;

import at.ac.tuwien.infosys.dsg.daios.framework.interfaces.IConstants;
import at.ac.tuwien.infosys.dsg.daios.framework.structs.DaiosOutputMessage;
import at.ac.tuwien.infosys.dsg.daios.wsdl.WSDLEncoding;
import at.ac.tuwien.infosys.dsg.daios.wsdl.interfaces.IWSDLMessage;
import at.ac.tuwien.infosys.dsg.daios.wsdl.typesystem.WSDLTypeTree;
import at.ac.tuwien.infosys.dsg.daiosPlugins.axis2.axiom.OMDocWrappedConverter;
import at.ac.tuwien.infosys.dsg.daiosPlugins.axis2.axiom.OMElementConverter;

/**
 * A concrete subclass of SOAPConverter. This is the concrete
 * instance used to convert messages in 'document' style invocations.
 * 
 * <p>
 * 
 * The functionality of this converter is implemented by the according
 * converter from the Axis2 backend.
 * 
 * @author philipp
 *
 */
public class SOAPDocConverter extends SOAPConverter {
	
	// a converter from the Axis2 backend
	private OMDocWrappedConverter docConverter = null;
	
	/**
	 * A private constructor. Use the factory method
	 * SOAPDocConverter.getInstance() to create new instances.
	 * 
	 * @param outputMsg The output message to associate with this
	 * converter.
	 * @param types The WSDL Type Tree defined in the WSDL message.
	 */
	private SOAPDocConverter(IWSDLMessage outputMsg, WSDLTypeTree types) {
		docConverter =
			(OMDocWrappedConverter)OMElementConverter.getInstance(
				new WSDLEncoding(IConstants.DOC_STYLE, IConstants.WRAPPED_STYLE),
				outputMsg, types);
	}
	
	/**
	 * The facory method used to construct new instances of SOAPDocConverter.
	 * 
	 * @param outputMsg The output message to associate with this
	 * converter.
	 * @param types The WSDL Type Tree defined in the WSDL message.
	 * @return A fresh instance of SOAPDocConverter.
	 */
	public static SOAPDocConverter getInstance(IWSDLMessage outputMsg,
			WSDLTypeTree types) {
		return new SOAPDocConverter(outputMsg, types);
	}
	
	/**
	 * Converts a XML response encoded as AXIOM model
	 * into a DaiosOutputMessage according to the
	 * output message associated with this converter.
	 * 
	 * @param node The XML document to convert.
	 * @param multirefs A list of 'multiref' elements. This
	 * is used only in 'rpc' style invocations.
	 * @return The XML document converted to a DaiosOutputMessage.
	 */
	public DaiosOutputMessage convert(OMElement node,
			List<OMElement> multirefs) {
		
		// re-use the OM document converter
		return docConverter.convert(node);
		
	}
	
}
